package jobs;

// 颜色接口
interface Color {
    void applyColor();
}

// 具体颜色：红色
class RedColor implements Color {
    @Override
    public void applyColor() {
        System.out.print("红色");
    }
}

// 具体颜色：蓝色
class BlueColor implements Color {
    @Override
    public void applyColor() {
        System.out.print("蓝色");
    }
}

// 抽象图形类
abstract class Shape{
    protected Color color;
    public Shape(Color color) {
        this.color = color;
    }
    public abstract void draw();
}

// 具体图形：圆形
class Circle1 extends Shape {
    public Circle1(Color color) {
        super(color);
    }
    @Override
    public void draw() {
        System.out.print("绘制");
        color.applyColor();
        System.out.println("的圆形");
    }
}

// 具体图形：矩形
class Rectangle extends Shape {
    public Rectangle(Color color) {
        super(color);
    }
    @Override
    public void draw() {
        System.out.print("绘制");
        color.applyColor();
        System.out.println("的矩形");
    }
}

// 测试类
public class BridgePatternTest {
    public static void main(String[] args) {
        Shape redCircle = new Circle1(new RedColor());
        Shape blueCircle = new Circle1(new BlueColor());
        Shape redRectangle = new Rectangle(new RedColor());
        Shape blueRectangle = new Rectangle(new BlueColor());

        redCircle.draw();
        blueCircle.draw();
        redRectangle.draw();
        blueRectangle.draw();
    }
}
